package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.ArticleRespond;
import com.jiutong.meipengdai.http.model.interfaces.ArticleBiz;
import com.jiutong.meipengdai.http.model.requests.ArticleRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 * 作用:
 * Created by 78 on 2017/7/6.
 */

public class ArticalPresent {

    private  Context context;
    private ArticleBiz mBiz;
    private ArticleRequest request;

    public  ArticalPresent(Context context,ArticleBiz mBiz){
        this.context = context;
        this.mBiz = mBiz;
        request = new ArticleRequest();
    }

    /**
     * 获取文章
     */
    public void getArticle() {

        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<ArticleRespond>() {
            @Override
            public void onNext(ArticleRespond subjects) {
                mBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("articleId", mBiz.getArticleId());

        request.getArticle(new ProgressSubscriber(onNextListener, context), fieldsMap);
    }
}
